package cn.com.self.apis.file.exception;


import org.springframework.http.HttpStatus;

/**
 * @author dongjiajie
 */
public class ServiceException extends RuntimeException {

    private static final long serialVersionUID = 1L;

    public static final int ENTITY_CONFLICT_ERROR = 1001;
    public static final int BAD_PARAMETER_ERROR = 1002;
    public static final int ENTITY_NOT_FOUND_ERROR = 1003;

    private int errorCode;
    private HttpStatus status;

    public ServiceException() {
        this.errorCode = HttpStatus.INTERNAL_SERVER_ERROR.value();
        this.status = HttpStatus.INTERNAL_SERVER_ERROR;
    }


    public ServiceException(int errorCode, String errorMessage) {
        super(errorMessage);
        this.status = HttpStatus.BAD_REQUEST;
        this.errorCode = errorCode;
    }

    public ServiceException(HttpStatus httpStatus, int errorCode, Throwable cause) {
        super(cause);
        this.status = httpStatus;
        this.errorCode = errorCode;
    }

    public ServiceException(HttpStatus httpStatus, Throwable cause) {
        super(cause);
        this.status = httpStatus;
        this.errorCode = httpStatus.value();
    }

    public ServiceException(Throwable cause) {
        super(cause);
        this.status = HttpStatus.BAD_REQUEST;
        this.errorCode = this.status.value();
    }

    public ServiceException(HttpStatus httpStatus, int errorCode, String errorMessage) {
        super(errorMessage);
        this.status = httpStatus;
        this.errorCode = errorCode;
    }

    public ServiceException(HttpStatus httpStatus, String errorMessage) {
        super(errorMessage);
        this.status = httpStatus;
        this.errorCode = httpStatus.value();
    }

    public int getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(int errorCode) {
        this.errorCode = errorCode;
    }

    public HttpStatus getStatus() {
        return status;
    }

    public void setStatus(HttpStatus status) {
        this.status = status;
    }
}
